package mysql

import "gorm.io/gorm"

type House struct {
	gorm.Model
	UserId      int64   `json:"userId"`
	Name        string  `json:"name"`
	Price       float64 `json:"price"`
	FacePrice   float64 `json:"facePrice"`
	HouseNumber int64   `json:"houseNumber"`
	ListingTime string  `json:"listingTime"`
	State       int64   `json:"state"`
}

func (h *House) HouseList(PriceFront, PriceAfter int64) (list []*House, err error) {
	DB = DB.Debug()
	if PriceFront > 0 {
		DB.Where("price >=", PriceFront)
	}
	if PriceAfter > 0 {
		DB.Where("price <=", PriceAfter)
	}
	err = DB.Debug().Order("listing_time DESC").Find(&list).Error
	return list, err
}

func (h *House) MyRelease(UserId int64) (list []*House, err error) {
	err = DB.Debug().Where("user_id = ?", UserId).Find(&list).Error
	return list, err
}
